package v1

import (
	"github.com/gin-gonic/gin"
	entityChat "github.com/wejectchen/ginblog/entity/entity_chat"
	entityChatModels "github.com/wejectchen/ginblog/entity/entity_chat_models"
	"github.com/wejectchen/ginblog/utils/errmsg"
	"net/http"
)

// BannerList 这里提供banner图接口
func BannerList(c *gin.Context) {
	resultJson := gin.H{}
	data, err := entityChat.BannerList()
	if err != nil {
		resultJson = gin.H{
			"status": errmsg.ERROR,
			"data":   nil,
		}
	} else {
		resultJson = gin.H{
			"status": errmsg.SUCCESS,
			"data":   data,
		}
	}
	c.JSON(http.StatusOK, resultJson)
}

// AddBanner 添加轮播图
func AddBanner(c *gin.Context) {
	var data entityChatModels.Banner
	err := c.ShouldBindJSON(&data)
	if err != nil {
		//fmt.Println("绑定失败", err)
		return
	}
	code := entityChat.CreatBanner(&data)
	c.JSON(http.StatusOK, gin.H{
		"status":  code,
		"data":    data,
		"message": errmsg.GetErrMsg(code),
	})
}
